<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateItemTypesTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('item_types', function(Blueprint $table)
        {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('name', 255)->index();
            $table->integer('group_id')->references('id')->on('groups')->index();
            $table->timestamps();            
        });

	Schema::table('items', function(Blueprint $table) 
        {
            $table->integer('item_type_id')->references('id')->on('item_types')->index();
        });
    }
    
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('item_types', function(Blueprint $table)
        {
            Schema::drop('item_types');            
        });
        Schema::table('items', function(Blueprint $table)
        {
            Schema::dropForeign('item_type_id');
        });        
    }

}